import threading
import time


class A:

	def __init__(self):
		self.lock = threading.RLock()

	def foo(self, b):
		self.lock.acquire()
		print("执行A")
		time.sleep(2)
		b.b_inner()
		self.lock.release()

	def a_inner(self):
		self.lock.acquire()
		print("执行A内部方法")
		time.sleep(2)
		self.lock.release()


class B:

	def __init__(self):
		self.lock = threading.RLock()

	def bar(self, a):
		self.lock.acquire()
		print("执行B")
		time.sleep(2)
		a.a_inner()
		self.lock.release()

	def b_inner(self):
		self.lock.acquire()
		print("执行B内部方法")
		time.sleep(2)
		self.lock.release()


class C(A, B):
	pass


a = A()
b = B()


def init():
	threading.current_thread().name = "主线程"
	# 调用a对象的foo()方法
	a.foo(b)
	print("进入了主线程之后")


def action():
	threading.current_thread().name = "副线程"
	# 调用b对象的bar()方法
	b.bar(a)
	print("进入了副线程之后")


# 以action为target启动新线程
threading.Thread(target=action).start()
# 调用init()函数
init()
